package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.*;
import com.woniuxy.mapper.*;
import com.woniuxy.service.HospitalEmployeeManagementsService;
import com.woniuxy.service.SaasService;
import com.woniuxy.util.PageParam;
import com.woniuxy.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * 员工管理
 * author：dongHeng
 */
@Service
public class HospitalEmployeeManagementServiceImpl implements HospitalEmployeeManagementsService , SaasService {
    @Autowired
    private TdeMapper tdeMapper;
    @Autowired
    private TrMapper trMapper;
    @Autowired
    private TPtMapper tPtMapper;
    @Autowired
    private TWorkMapper tWorkMapper;
    @Autowired
    private UserMapper userMapper;
    @Override
    public ResponseData<?> queryTWorkAll(PageParam<TWork> pageParam) {
        PageHelper.startPage(pageParam.getPageNum(),pageParam.getPageSize());

        List<TWork> tWorkList=tWorkMapper.queryAll(pageParam.getParam());
        PageInfo pageInfo =new PageInfo(tWorkList);

        return new ResponseData<>().ok(pageInfo);
    }

    @Override
    public ResponseData<?> updateTWork(TWork tWork) {
        tWorkMapper.update(tWork);
        return new ResponseData<>().ok();
    }

    @Override
    public ResponseData<?> addTWork(TWork tWork) {

        tWorkMapper.addTWork(tWork);
        User user=new User();
        user.setId(tWork.getId());
        user.setAccount(tWork.getWkName());
        user.setPassword(tWork.getWkPassword());
        user.setPhone(tWork.getWkPhone());
        userMapper.addUser(user);
        return new ResponseData<>().ok();
    }

    @Override
    public ResponseData<?> queryPt() {
        List<TPt> tPtList = tPtMapper.queryAll();
        return new ResponseData<>().ok(tPtList);
    }

    @Override
    public ResponseData<?> queryDe(Integer wkHdepartmentid) {
         List<Tde> tdeList=tdeMapper.queryByTPtId(wkHdepartmentid);
        return new ResponseData<>().ok(tdeList);
    }

    @Override
    public ResponseData<?> queryRole(Integer wkDepartmentid) {
        List<Tr> trList = trMapper.queryByHpId(wkDepartmentid);
        return new ResponseData<>().ok(trList);
    }

    @Override
    public ResponseData<?> queryByEmpId(Integer id) {
        TWork tWork = tWorkMapper.queryById(id);
        return new ResponseData<>().ok(tWork);
    }

    @Override
    public ResponseData<?> queryRoleAll() {
        List<Tr> trList= trMapper.queryRoleAll();
        return new ResponseData<>().ok(trList);
    }
}
